package org.lc.solon.cmd.plugin.scan;

import org.lc.solon.cmd.ResultHandler;
import org.lc.solon.cmd.ResultManager;
import org.lc.solon.cmd.util.CmdOutUtil;
import org.noear.solon.annotation.Component;

import java.util.Collection;

@Component(index = 100)
public class CollectionHandler implements ResultHandler {

    @Override
    public Object handle(Object result, String line) {
        if (result instanceof Collection) {
            ((Collection<?>) result).forEach(item -> {
                ResultManager.handleResult(item, line);
                CmdOutUtil.writeln();
            });
            return null;
        }
        return result;
    }
}
